package com.community.web.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.community.common.exception.NeusoftException;
import com.community.common.result.ResultCodeEnum;
import com.community.model.entity.Carts;
import com.community.model.entity.GoodsStore;
import com.community.web.user.service.GoodsStoreService;
import com.community.web.user.mapper.GoodsStoreMapper;
import org.springframework.stereotype.Service;

/**
* @author admin
* @description 针对表【goods_store】的数据库操作Service实现
* @createDate 2024-07-02 10:56:56
*/
@Service
public class GoodsStoreServiceImpl extends ServiceImpl<GoodsStoreMapper, GoodsStore>
    implements GoodsStoreService{

    @Override
    public void checkStock(Carts carts) {
        //判断商品库存
        LambdaQueryWrapper<GoodsStore> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GoodsStore::getGoodsNo, carts.getGoodsNo());
        queryWrapper.eq(GoodsStore::getStoreNo, carts.getStoreNo());
        GoodsStore goodsStore = super.getOne(queryWrapper);
        Integer goodsStock = goodsStore.getGoodsStock();
        if (goodsStock < carts.getAmount()){
            throw new NeusoftException(ResultCodeEnum.OVER_STOCK);
        }
    }
}




